package org.jeecg.glr.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.glr.entity.GlrLedMember;
import org.jeecg.glr.mapper.GlrLedMemberMapper;
import org.jeecg.glr.service.IGlrLedMemberService;
import org.jeecg.glr.util.GLRConstant;
import org.jeecg.glr.util.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: LED屏资源表
 * @Author: jeecg-boot
 * @Date:   2020-02-25
 * @Version: V1.0
 */
@Service
public class GlrLedMemberServiceImpl extends ServiceImpl<GlrLedMemberMapper, GlrLedMember> implements IGlrLedMemberService {

    @Resource GlrLedMemberMapper glrLedMemberMapper;
    @Override
    public List<String> getResourceByColumnId(String columnId) {
        return glrLedMemberMapper.getResourceByColumnId(columnId);
    }

    @Override
    public void bingResource(GlrLedMember domain) {


        Integer orderCode=glrLedMemberMapper.getGlrLedMemberorderCode(domain.getColumnId());
        if(orderCode==null){
            orderCode=0;
        }
        if(StringUtil.isNotEmpty(domain.getIds())){
            String [] ids=domain.getIds().split(",");
            for(int i=0;i<ids.length;i++){
                if(StringUtil.isNotEmpty(ids[i])){
                    orderCode++;
                    GlrLedMember r = new GlrLedMember();
                    r.setMemberId(ids[i]);
                    r.setMemberType(GLRConstant.GLR_LED_MEMBER_TYPE_2);
                    r.setOrderCode(orderCode);
                    r.setColumnId(domain.getColumnId());
                    super.save(r);
                }
            }
        }
    }

    @Override
    public void bingLed(GlrLedMember domain) {
        if(StringUtil.isNotEmpty(domain.getIds())){
            String [] ids=domain.getIds().split(",");
            for(int i=0;i<ids.length;i++){
                if(StringUtil.isNotEmpty(ids[i])){
                    GlrLedMember r = new GlrLedMember();
                    r.setMemberId(ids[i]);
                    r.setMemberType(GLRConstant.GLR_LED_MEMBER_TYPE_1);
                    r.setColumnId(domain.getColumnId());
                    super.save(r);
                }
            }
        }
    }

    @Override
    public List<String> getLedByColumnId(String columnId) {
        return glrLedMemberMapper.getLedByColumnId(columnId);
    }

    @Override
    public void delLedMemberByColumnId(String id) {
        glrLedMemberMapper.delLedMemberByColumnId(id);
    }
}
